﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Web.Profile;
using IronOne.SalesOne.BusinessObjects;
using System.Configuration;
using Facade;
using System.Collections;
using System.Data;

namespace IronOne.SalesOne.SalesOneWeb.ContactManagement
{
    public partial class AssignSuspects : SOSecurityPage,IntTest,IDataPage
    {
        public static List<Branch> brnch;
        public static List<SalesOneUnit> un;
        public static List<string> so;

        private static int pageNo = 1;


        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                ValidateUserCredentials(Request.Url.LocalPath);

                if (!IsPostBack)
                {
                    FillDropDown("Branch");
                    FillDropDown("Unit");
                    FillDropDown("SO");
                }
            }
            catch (Exception ex)
            {

                //lblError.Text = ex.Message;
                //lblError.ForeColor = System.Drawing.Color.Red;
            }
            

        }

       

        public void FillDropDown(string type)
        {
            try
            {
                StructureFacade fac = new StructureFacade();
                string curUser = User.Identity.Name;
                int[] strUser = fac.GetStructureForUser(curUser);
                ContactSearch cs = new ContactSearch();

                UserInformation ui = fac.GetUserInformation(User.Identity.Name);

                int usrType = strUser[0];
                int node = strUser[1];

                ListItem itt = new ListItem("Select...", "-1");

                if (usrType == 1)
                {
                    //HQ
                    switch (type)
                    {
                        case "Branch":
                            brnch = fac.GetBranches("BranchId ASC");
                            Branch brsel = new Branch();
                            Branch brsela = new Branch();
                            brsel.BranchId = -1;
                            brsel.BranchName = "Select...";
                            brsela.BranchId = -2;
                            brsela.BranchName = "Select All";
                            brnch.Insert(0, brsel);
                            brnch.Insert(1, brsela);
                            drpBranch.DataSource = brnch;
                            drpBranch.DataTextField = "BranchName";
                            drpBranch.DataValueField = "BranchId";
                            drpBranch.DataBind();
                            break;

                        case "Unit":
                            if (drpBranch.SelectedValue != "-1")
                            {
                                un = fac.GetUnitsInBranch(Convert.ToInt32(drpBranch.SelectedValue));
                                SalesOneUnit unSel = new SalesOneUnit();
                                SalesOneUnit unSela = new SalesOneUnit();
                                unSel.UnitId = -1;
                                unSel.Name = "Select...";
                                unSela.BranchId = -2;
                                unSela.Name = "Select All";
                                un.Insert(0, unSel);
                                un.Insert(1, unSela);
                                drpUnit.DataSource = un;
                                drpUnit.DataTextField = "Name";
                                drpUnit.DataValueField = "UnitId";
                                drpUnit.DataBind();
                            }
                            else
                            {
                                drpUnit.Items.Clear();
                                drpUnit.Items.Insert(0, itt);
                            }
                            break;


                        case "SO":
                            if (drpUnit.SelectedValue != "-1")
                            {
                                so = fac.GetSOsInUnit(Convert.ToInt32(drpUnit.SelectedValue));
                                //drpSoCode.DataSource = so;
                                string srl = "Select...";
                                string sra = "Select All";
                                so.Insert(0, srl);
                                so.Insert(1, sra);
                                drpSoCode.DataSource = so;
                                //drpSoCode.DataTextField = "BranchName";
                                //drpBranch.DataValueField = "BranchId";
                                drpSoCode.DataBind();
                            }
                            else
                            {
                                drpSoCode.Items.Clear();
                                drpSoCode.Items.Insert(0, itt);
                            }
                            break;
                        default:
                            break;
                    }
                }
                else if (usrType == 2)
                {
                    //Group
                    switch (type)
                    {
                        case "Branch":
                            brnch = fac.GetBranchesForGroup(node);
                            Branch brsel = new Branch();
                            Branch brsela = new Branch();
                            brsel.BranchId = -1;
                            brsel.BranchName = "Select...";
                            brsela.BranchId = -2;
                            brsela.BranchName = "Select All";
                            brnch.Insert(0, brsel);
                            brnch.Insert(1, brsela);
                            drpBranch.DataSource = brnch;
                            drpBranch.DataTextField = "BranchName";
                            drpBranch.DataValueField = "BranchId";
                            drpBranch.DataBind();
                            break;

                        case "Unit":
                            if (drpBranch.SelectedValue != "-1")
                            {
                                un = fac.GetUnitsInBranch(Convert.ToInt32(drpBranch.SelectedValue));
                                SalesOneUnit unSel = new SalesOneUnit();
                                SalesOneUnit unSela = new SalesOneUnit();
                                unSel.UnitId = -1;
                                unSel.Name = "Select...";
                                unSela.BranchId = -2;
                                unSela.Name = "Select All";
                                un.Insert(0, unSel);
                                un.Insert(1, unSela);
                                drpUnit.DataSource = un;
                                drpUnit.DataTextField = "Name";
                                drpUnit.DataValueField = "UnitId";
                                drpUnit.DataBind();
                            }
                            else
                            {
                                drpUnit.Items.Clear();
                                drpUnit.Items.Insert(0, itt);
                            }
                            break;


                        case "SO":
                            if (drpUnit.SelectedValue != "-1")
                            {
                                if (!string.IsNullOrEmpty(drpUnit.SelectedValue))
                                {
                                    so = fac.GetSOsInUnit(Convert.ToInt32(drpUnit.SelectedValue));
                                    //drpSoCode.DataSource = so;
                                    string srl = "Select...";
                                    string sra = "Select All";
                                    so.Insert(0, srl);
                                    so.Insert(1, sra);
                                    drpSoCode.DataSource = so;
                                    //drpSoCode.DataTextField = "BranchName";
                                    //drpBranch.DataValueField = "BranchId";
                                    drpSoCode.DataBind();
                                }

                            }
                            else
                            {
                                drpSoCode.Items.Clear();
                                drpSoCode.Items.Insert(0, itt);
                            }
                            break;
                        default:
                            break;
                    }

                }
                else if (usrType == 3)
                {
                    //Branch
                    switch (type)
                    {
                        case "Branch":
                            Branch brnch = fac.GetBranch(node);
                            ListItem it = new ListItem(brnch.BranchName, brnch.BranchId.ToString());
                            drpBranch.Items.Add(it);
                            //drpBranch.DataTextField = brnch.BranchName;
                            //drpBranch.DataValueField = brnch.BranchId.ToString();
                            //drpBranch.DataBind();
                            List<Branch> br = new List<Branch>();
                            br.Add(fac.GetBranch(Convert.ToInt32(drpBranch.SelectedValue)));
                            cs.Unt = un;
                            cs.Brnch = br;
                            //cs.SOCode = null;

                            int[] susNos = { 0, 7 };
                            UCGrid1.SetDataSource(SuspectSource(br, pageNo), susNos);

                            drpBranch.Enabled = false;
                            break;

                        case "Unit":
                            if (drpBranch.SelectedValue != "-1")
                            {
                                un = fac.GetUnitsInBranch(Convert.ToInt32(drpBranch.SelectedValue));
                                SalesOneUnit unSel = new SalesOneUnit();
                                SalesOneUnit unSela = new SalesOneUnit();
                                unSel.UnitId = -1;
                                unSel.Name = "Select...";
                                unSela.BranchId = -2;
                                unSela.Name = "Select All";
                                un.Insert(0, unSel);
                                un.Insert(1, unSela);
                                drpUnit.DataSource = un;
                                drpUnit.DataTextField = "Name";
                                drpUnit.DataValueField = "UnitId";
                                drpUnit.DataBind();
                            }
                            else
                            {
                                drpUnit.Items.Clear();
                                drpUnit.Items.Insert(0, itt);
                            }
                            break;


                        case "SO":
                            if (drpUnit.SelectedValue != "-1")
                            {
                                so = fac.GetSOsInUnit(Convert.ToInt32(drpUnit.SelectedValue));
                                //drpSoCode.DataSource = so;
                                string srl = "Select...";
                                string sra = "Select All";
                                so.Insert(0, srl);
                                so.Insert(1, sra);
                                drpSoCode.DataSource = so;
                                //drpSoCode.DataTextField = "BranchName";
                                //drpBranch.DataValueField = "BranchId";
                                drpSoCode.DataBind();
                            }
                            else
                            {
                                drpSoCode.Items.Clear();
                                drpSoCode.Items.Insert(0, itt);
                            }
                            break;
                        default:
                            break;
                    }
                }
                else if (usrType == 4)
                {
                    //unit
                    switch (type)
                    {
                        case "Branch":
                            brnch = fac.GetBranchesForGroup((int)ui.GroupId);
                            //Branch brnc = fac.GetBranch((int)ui.BranchId);
                            drpBranch.DataSource = brnch;
                            drpBranch.DataTextField = "BranchName";
                            drpBranch.DataValueField = "BranchId";
                            drpBranch.DataBind();
                            drpBranch.SelectedValue = ui.BranchId.Value.ToString();
                            drpBranch.Enabled = false;

                            //List<Branch> br = new List<Branch>();
                            //br.Add(fac.GetBranch(Convert.ToInt32(drpBranch.SelectedValue)));


                            break;

                        case "Unit":
                            if (drpBranch.SelectedValue != "-1")
                            {
                                SalesOneUnit un = fac.GetUnit(node);
                                ListItem it = new ListItem(un.Name, un.UnitId.ToString());
                                drpUnit.Items.Add(it);
                                drpUnit.Enabled = false;

                                List<SalesOneUnit> unt = new List<SalesOneUnit>();
                                unt.Add(fac.GetUnit(Convert.ToInt32(drpUnit.SelectedValue)));
                                cs.Unt = unt;
                                cs.Brnch = brnch;
                                cs.SOCode = null;

                                int[] susNos = { 0, 7 };
                                UCGrid1.SetDataSource(SuspectSource(brnch, pageNo), susNos);

                            }
                            else
                            {
                                drpUnit.Items.Clear();
                                drpUnit.Items.Insert(0, itt);
                            }
                            break;


                        case "SO":
                            if (drpUnit.SelectedValue != "-1" )
                            {
                                so = fac.GetSOsInUnit(Convert.ToInt32(drpUnit.SelectedValue));
                                //so.com
                                //= fac.GetSOsInUnit(Convert.ToInt32(drpUnit.SelectedValue))
                                //drpSoCode.DataSource = so;
                                string srl = "Select...";
                                string sra = "Select All";
                                so.Insert(0, srl);
                                so.Insert(1, sra);
                                drpSoCode.DataSource = so;
                                //drpSoCode.DataTextField = "BranchName";
                                //drpBranch.DataValueField = "BranchId";
                                drpSoCode.DataBind();
                            }
                            else
                            {
                                drpSoCode.Items.Clear();
                                drpSoCode.Items.Insert(0, itt);
                            }
                            break;
                        default:
                            break;
                    }
                }
            }
            catch (Exception)
            {
                

            }
            



        }




        private DataTable SuspectSource(List<Branch> br, int pageNo)
        {
            try
            {
                StructureFacade fac = new StructureFacade();
                CustomerFacade cusFac = new CustomerFacade();

                DataTable usrTable = new DataTable();
                DataRow newRow;

                usrTable.Columns.Add("Id No");
                usrTable.Columns.Add("SO Code");
                usrTable.Columns.Add("Name");
                usrTable.Columns.Add("Other Name");
                usrTable.Columns.Add("Last Updated Date");
                usrTable.Columns.Add("susp id");
                //hidden columns


                string idNo = "";
                string name = "";
                string otherName = "";
                string lstUpdatedTime = "";


                if (pageNo == 1)
                {
                    UCGrid1.SetText("1");
                }

                if (br.Count >0 )
                {
                    List<Customer> list = cusFac.GetSuspectsForBranch(br, pageNo);
                     if (list.Count == Convert.ToInt32(ConfigurationManager.AppSettings["GridCount"]))
                    {
                        UCGrid1.IsLastPage = (cusFac.GetSuspectsForBranch(br, pageNo + 1)).Count > 0 ? false : true;
                    }

                    foreach (Customer cus in list)
                    {

                        if (cus != null && !string.IsNullOrEmpty(cus.CustomerId))
                        {
                            //Customer cus = cusFac.GetCustomer(susp.CustomerId);
                            idNo = cus.IdNumber;
                            name = cus.FirstName;
                            otherName = cus.OtherName;
                            lstUpdatedTime = cus.LastUpdated;
                            //Suspect sus = cusFac.GetSuspForCustomer(cus.CustomerId);

                            newRow = usrTable.NewRow();
                            newRow[0] = idNo;
                            newRow[1] = cus.SoCode;
                            //cus.SoCode;
                            //cusFac.GetSOForCustomer(cus.CustomerId);
                            newRow[2] = name;
                            newRow[3] = otherName;
                            newRow[4] = lstUpdatedTime;
                            newRow[5] = cus.CustomerId;


                            usrTable.Rows.Add(newRow);
                        }



                    }

                    if (usrTable.Rows.Count > 0)
                    {
                        btnAssign.Visible = true;
                    }
                    else
                    {
                        MassageSummery("IIS504");
                        btnAssign.Visible = false;
                    }
                }
                else
                {
                    MassageSummery("IIS504");
                    btnAssign.Visible = false;
                }
                


                return usrTable;
            }
            catch (Exception)
            {
                return null;
            }
            
        }

        protected void drpBranch_SelectedIndexChanged(object sender, EventArgs e)
        {


            try
            {
                FillDropDown("Unit");
                FillDropDown("SO");

                StructureFacade fac = new StructureFacade();
                //ContactSearch cs = new ContactSearch();

                List<Branch> br = new List<Branch>();
                List<SalesOneUnit> unt = new List<SalesOneUnit>();
                List<string> soCode = new List<string>();

                if (drpBranch.SelectedIndex != -1)
                {
                    if (drpBranch.SelectedItem.Text == "Select All")
                    {
                        brnch.RemoveRange(0, 2);
                        br = brnch;

                        foreach (Branch Unbr in br)
                        {
                            unt.AddRange(fac.GetUnitsForBranch(Unbr.BranchId));
                        }

                    }
                    else if (0 != drpBranch.SelectedValue.CompareTo("-1"))
                    {
                        br.Add(fac.GetBranch(Convert.ToInt32(drpBranch.SelectedValue)));

                        un.RemoveRange(0, 2);
                        unt = un;
                    }


                }


                //SalesOneUnit unSel = new SalesOneUnit();
                //SalesOneUnit unSela = new SalesOneUnit();
                //unSel.UnitId = -1;
                //unSel.Name = "Select...";
                //unSela.BranchId = -2;
                //unSela.Name = "Select All";
                //unt.Insert(0, unSel);
                //unt.Insert(1, unSela);

                //drpUnit.DataSource = unt;
                //drpUnit.DataBind();




                //cs.Unt = unt;
                //cs.Brnch = null;
                //cs.SOCode = null;

                int[] susNos = { 0, 7 };

                

                UCGrid1.SetDataSource(SuspectSource(br, 1), susNos);

            }
            catch (Exception)
            {

            }
               
            
            


        }

        protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                StructureFacade fac = new StructureFacade();
                ContactSearch cs = new ContactSearch();

                List<Branch> br = new List<Branch>();
                List<SalesOneUnit> unt = new List<SalesOneUnit>();
                List<string> soCode = new List<string>();

                if (drpBranch.SelectedIndex != -1)
                {
                    if (drpBranch.SelectedItem.Text == "Select All")
                    {
                        if (brnch.Count > 0)
                        {
                            brnch.RemoveRange(0, 2);
                        }

                        br = brnch;
                    }
                    else if (0 != drpBranch.SelectedValue.CompareTo("-1"))
                    {
                        br.Add(fac.GetBranch(Convert.ToInt32(drpBranch.SelectedValue)));
                    }


                }

                if (drpUnit.SelectedIndex != -1)
                {
                    if (drpUnit.SelectedItem.Text == "Select All")
                    {
                        if (un.Count > 0)
                        {
                            un.RemoveRange(0, 2);
                        }

                        unt = un;

                    }
                    else if (0 != drpUnit.SelectedValue.CompareTo("-1"))
                    {
                        unt.Add(fac.GetUnit(Convert.ToInt32(drpUnit.SelectedValue)));
                    }


                }






                //unt.Add(fac.GetUnit(Convert.ToInt32(drpUnit.SelectedValue)));
                //cs.Unt = unt;
                cs.Brnch = br;
                //cs.SOCode = null;

                FillDropDown("SO");
            }
            catch (Exception)
            {
                
                throw;
            }
            

            //int[] susNos = { 0,7 };
            //UCGrid1.SetDataSource(SuspectSource(br,1), susNos);
        }


        protected void drpSoCode_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void btnAssign_Click(object sender, EventArgs e)
        {

            try
            {
                GridView gr = (GridView)UCGrid1.FindControl("grdUsers");
                CustomerFacade cFac = new CustomerFacade();

                string susId = string.Empty;
                string soCode = "";
                string fails = string.Empty;
                string success = string.Empty;
                foreach (GridViewRow row in gr.Rows)
                {
                    CheckBox chk = (CheckBox)row.Cells[0].FindControl("chkUsers");
                    if (chk != null && chk.Checked == true)
                    {
                        soCode = drpSoCode.SelectedValue;

                        susId = row.Cells[7].Text;
                        Customer cus = cFac.GetCustomer(susId);

                        cus.SoCode = soCode;
                        int i = 0;
                        if (soCode == "Select..." || soCode == "Select All" || soCode == string.Empty)
                        {
                            MassageSummery("IIS502");
                        }
                        else
                        {
                            i = cFac.UpdateUser(cus);
                            
                        }
                        
                           // UpdateSuspect(sus);

                       

                        if (i == 1)
                        {
                            
                            MassageSummery("IIS401");

                            
                        }
                        else
                        {
                            MassageSummery("IIS502");
                            //fails += row.Cells[4].Text + " ";
                        }
                        
                        int[] susNos = { 0, 7 };

                    }
                }

                
                StructureFacade fac = new StructureFacade();
                ContactSearch cs = new ContactSearch();

                List<Branch> br = new List<Branch>();
                List<SalesOneUnit> unt = new List<SalesOneUnit>();
                List<string> soC = new List<string>();

                if (drpBranch.SelectedIndex != -1)
                {
                    if (drpBranch.SelectedItem.Text == "Select All")
                    {
                        brnch.RemoveRange(0, 2);
                        br = brnch;
                    }
                    else if (0 != drpBranch.SelectedValue.CompareTo("-1"))
                    {
                        br.Add(fac.GetBranch(Convert.ToInt32(drpBranch.SelectedValue)));
                    }


                }

                if (drpUnit.SelectedIndex != -1)
                {
                    if (drpUnit.SelectedItem.Text == "Select All")
                    {

                        un.RemoveRange(0, 2);
                        unt = un;


                    }
                    else if (0 != drpUnit.SelectedValue.CompareTo("-1"))
                    {
                        unt.Add(fac.GetUnit(Convert.ToInt32(drpUnit.SelectedValue)));
                    }


                }

                cs.Unt = unt;
                cs.Brnch = br;
                cs.SOCode = null;

                int[] su = { 0, 7 };
                UCGrid1.SetDataSource(SuspectSource(br,pageNo), su);
            }
            catch (Exception)
            {
                
                throw;
            }
            
            
            
        }

        
        //protected void drpBranch_SelectedIndexChanged(object sender, EventArgs e)
        //{

        //    FillDropDown("Unit");



        //    StructureFacade fac = new StructureFacade();
        //    ContactSearch cs = new ContactSearch();

        //    List<Branch> br = new List<Branch>();
        //    List<SalesOneUnit> unt = new List<SalesOneUnit>();
        //    List<string> soCode = new List<string>();

        //    if (drpBranch.SelectedIndex != -1)
        //    {
        //        if (drpBranch.SelectedItem.Text == "Select All")
        //        {
        //            brnch.RemoveRange(0, 2);
        //            br = brnch;

        //            foreach (Branch Unbr in br)
        //            {
        //                unt.AddRange(fac.GetUnitsForBranch(Unbr.BranchId));
        //            }

        //        }
        //        else if (0 != drpBranch.SelectedValue.CompareTo("-1"))
        //        {
        //            br.Add(fac.GetBranch(Convert.ToInt32(drpBranch.SelectedValue)));

        //            un.RemoveRange(0, 2);
        //            unt = un;
        //        }


        //    }


        //    SalesOneUnit unSel = new SalesOneUnit();
        //    SalesOneUnit unSela = new SalesOneUnit();
        //    unSel.UnitId = -1;
        //    unSel.Name = "Select";
        //    unSela.BranchId = -2;
        //    unSela.Name = "Select All";
        //    unt.Insert(0, unSel);
        //    unt.Insert(1, unSela);

        //    drpUnit.DataSource = unt;
        //    drpUnit.DataBind();




        //    cs.Unt = unt;
        //    cs.Brnch = null;
        //    cs.SOCode = null;

        //    int[] susNos = { 0, 7 };
        //    UCGrid1.SetDataSource(SuspectSource(cs, 1), susNos);



        //}

        #region IntTest Members

        void IntTest.Next()
        {
            if (pageNo != 1)
            {
                pageNo = pageNo + 1;
                UCGrid1.SetText(pageNo.ToString());

            }
            else
            {
                pageNo = 2;
                UCGrid1.SetText("2");

            }

            StructureFacade fac = new StructureFacade();
            ContactSearch cs = new ContactSearch();

            List<Branch> br = new List<Branch>();
            List<SalesOneUnit> unt = new List<SalesOneUnit>();
            List<string> soCode = new List<string>();

            if (drpBranch.SelectedIndex != -1)
            {
                if (drpBranch.SelectedItem.Text == "Select All")
                {
                    brnch.RemoveRange(0, 2);
                    br = brnch;
                }
                else if (0 != drpBranch.SelectedValue.CompareTo("-1"))
                {
                    br.Add(fac.GetBranch(Convert.ToInt32(drpBranch.SelectedValue)));
                }


            }

            if (drpUnit.SelectedIndex != -1)
            {
                if (drpUnit.SelectedItem.Text == "Select All")
                {

                    un.RemoveRange(0, 2);
                    unt = un;


                }
                else if (0 != drpUnit.SelectedValue.CompareTo("-1"))
                {
                    unt.Add(fac.GetUnit(Convert.ToInt32(drpUnit.SelectedValue)));
                }


            }

            //unt.Add(fac.GetUnit(Convert.ToInt32(drpUnit.SelectedValue)));
            cs.Unt = unt;
            cs.Brnch = br;
            cs.SOCode = null;

            int[] susNos = { 0, 7 };
            UCGrid1.SetDataSource(SuspectSource(br, pageNo), susNos);

        }

        void IntTest.Previous()
        {
            if (pageNo != 1)
            {
                pageNo = pageNo - 1;
                UCGrid1.SetText(pageNo.ToString());

                StructureFacade fac = new StructureFacade();
                ContactSearch cs = new ContactSearch();

                List<Branch> br = new List<Branch>();
                List<SalesOneUnit> unt = new List<SalesOneUnit>();
                List<string> soCode = new List<string>();

                if (drpBranch.SelectedIndex != -1)
                {
                    if (drpBranch.SelectedItem.Text == "Select All")
                    {
                        brnch.RemoveRange(0, 2);
                        br = brnch;
                    }
                    else if (0 != drpBranch.SelectedValue.CompareTo("-1"))
                    {
                        br.Add(fac.GetBranch(Convert.ToInt32(drpBranch.SelectedValue)));
                    }


                }

                if (drpUnit.SelectedIndex != -1)
                {
                    if (drpUnit.SelectedItem.Text == "Select All")
                    {

                        un.RemoveRange(0, 2);
                        unt = un;


                    }
                    else if (0 != drpUnit.SelectedValue.CompareTo("-1"))
                    {
                        unt.Add(fac.GetUnit(Convert.ToInt32(drpUnit.SelectedValue)));
                    }


                }

                //unt.Add(fac.GetUnit(Convert.ToInt32(drpUnit.SelectedValue)));
                cs.Unt = unt;
                cs.Brnch = br;
                cs.SOCode = null;

                int[] susNos = { 0, 7 };
                UCGrid1.SetDataSource(SuspectSource(br, pageNo), susNos);
            }
        }

        void IntTest.Go()
        {
            int p = int.Parse(UCGrid1.GetText());
            if (p != 0)
            {
                try
                {
                    StructureFacade fac = new StructureFacade();
                    ContactSearch cs = new ContactSearch();

                    List<Branch> br = new List<Branch>();
                    List<SalesOneUnit> unt = new List<SalesOneUnit>();
                    List<string> soCode = new List<string>();

                    if (drpBranch.SelectedIndex != -1)
                    {
                        if (drpBranch.SelectedItem.Text == "Select All")
                        {
                            brnch.RemoveRange(0, 2);
                            br = brnch;
                        }
                        else if (0 != drpBranch.SelectedValue.CompareTo("-1"))
                        {
                            br.Add(fac.GetBranch(Convert.ToInt32(drpBranch.SelectedValue)));
                        }


                    }

                    if (drpUnit.SelectedIndex != -1)
                    {
                        if (drpUnit.SelectedItem.Text == "Select All")
                        {

                            un.RemoveRange(0, 2);
                            unt = un;


                        }
                        else if (0 != drpUnit.SelectedValue.CompareTo("-1"))
                        {
                            unt.Add(fac.GetUnit(Convert.ToInt32(drpUnit.SelectedValue)));
                        }


                    }

                    //unt.Add(fac.GetUnit(Convert.ToInt32(drpUnit.SelectedValue)));
                    cs.Unt = unt;
                    cs.Brnch = br;
                    cs.SOCode = null;

                    int[] susNos = { 0, 7 };
                    UCGrid1.SetDataSource(SuspectSource(br, p), susNos);
                    pageNo = p;
                }
                catch (Exception)
                {

                    throw;
                }


            }
        }

        #endregion

        #region IDataPage Members

        public void Create()
        {

        }

        public void View()
        {

        }

        public void Update()
        {

        }

        public void Delete()
        {

        }

        public void Cancel()
        {

        }

        public void GetId(GridViewRow row)
        {

        }

        #endregion
    }
}
